/**
 * ...
 * @author Thot
 */

function ApplicationProxy()
{
	this.init( ApplicationProxy.NAME, new Array() );
}

POO.extend( ApplicationProxy, Proxy );


	// static
	ApplicationProxy.NAME = "ApplicationProxy";


	//public
	ApplicationProxy.prototype.currentAnim 		= "";
	ApplicationProxy.prototype.currentLayer 	= "";
	ApplicationProxy.prototype.currentMap 		= "";
	ApplicationProxy.prototype._currentProject  = null;
	ApplicationProxy.prototype._loader			= null;
	
	
	ApplicationProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this.listenNotifications();
		this._loader = new Loader();
		this._loader.signal.addListener( Loader.LOAD_COMPLETE, this._loadProjectCompleteHandler, this );
	};
	
	ApplicationProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.SELECT_ANIMATION, this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_LAYER, 	this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_MAP, 		this.onNotification );
	};

	ApplicationProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.SELECT_ANIMATION:	this.currentAnim 	= p_data;	break;
			case ApplicationNotification.SELECT_LAYER:		this.currentLayer 	= p_data;	break;
			case ApplicationNotification.SELECT_MAP:		this.currentMap 	= p_data;	break;
		}
	};
	
	
	ApplicationProxy.prototype.loadProject = function( p_url )
	{
		this._loader.load( p_url );
	};
	
	ApplicationProxy.prototype._loadProjectCompleteHandler = function()
	{
		try
		{
			this._currentProject = eval( this._loader.getData() );
		}
		catch(error)
		{
			this._currentProject = this.getDefaultProject();
		}
		
		this.getFacade().sendNotification( ApplicationNotification.LOAD_PROJECT_COMPLETE );
	};
	
	ApplicationProxy.prototype.getAnimationsList = function()
	{
		return this._currentProject.getAnimationsList();
	};
	
	ApplicationProxy.prototype.getTexturesList = function()
	{
		return this._currentProject.getTexturesList();
	};
	
	ApplicationProxy.prototype.getMapsList = function()
	{
		return this._currentProject.getMapsList();
	};
	
	ApplicationProxy.prototype.getProjectName = function()
	{
		return this._currentProject.name;
	};
	
	ApplicationProxy.prototype.getDefaultProject = function()
	{
		var project = new Object();
		project.name = "default";

		project.getAnimationsList = function(){return [];};
		project.getTexturesList = function(){return [];};
		project.getMapsList = function(){return [];};

		return project;
	};

	
	